package com.hznu.ez4life.modules.controller;


import com.hznu.ez4life.modules.entity.Helpitem;
import com.hznu.ez4life.modules.service.HelpitemService;
import com.hznu.ez4life.myBeans.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author DragonDoor
 * @since 2019-07-25
 */
@RestController
@EnableAutoConfiguration
@RequestMapping("/helpitem")
public class HelpitemController {

    @Autowired
    HelpitemService helpitemService;

    @PostMapping("/addOne")
    public R addOne(@RequestBody Helpitem helpitem)
    {
        try
        {
            helpitemService.addOne(helpitem);
            return R.ok();
        }catch (Exception e)
        {
            e.printStackTrace();
            return R.error();
        }
    }



    @GetMapping("/findListByUserId/{userId}")
    public R findListByUserId(@PathVariable Integer userId)
    {
        try
        {
            return R.ok().put("helpitemList",helpitemService.findBatchByUserid(userId));
        }catch (Exception e)
        {
            e.printStackTrace();
            return R.error();
        }
    }

    @PostMapping("/findBatchByCondition")
    public R findBatchByCondition(@RequestBody Helpitem helpitem)
    {
        try
        {
            return R.ok().put("helpItemList",helpitemService.findBatchByCondition(helpitem));
        }catch (Exception e)
        {
            e.printStackTrace();
            return R.error();
        }
    }

    @GetMapping("/removeById/{id}")
    public R removeById(@PathVariable Integer id)
    {
        try
        {
            helpitemService.removeOne(id);
            return R.ok();
        }catch (Exception e)
        {
            e.printStackTrace();
            return R.error();
        }
    }
}

